package com.example.it.review.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

/**
 * Created by 鲁迅认识的那只猹 on 9/27/2017 8:35 AM.
 * Emial 1258730808@qq.com
 * Desc:
 */

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyHolder> {

    private Context context;
    private List<String> stringList;
    private View.OnClickListener onClickListener;

    public MyAdapter(Context context, List<String> stringList, View.OnClickListener onClickListener) {
        this.context = context;
        this.stringList = stringList;
        this.onClickListener = onClickListener;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(this.context).inflate(android.R.layout.simple_list_item_activated_1, parent, false);
        return new MyHolder(view);
    }
    
    @Override
    public void onBindViewHolder(MyHolder holder, int position) {
        String value = this.stringList.get(position);
        holder.textView.setText(value);
        holder.itemView.setOnClickListener(this.onClickListener);
    }

    @Override
    public int getItemCount() {
        return stringList.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {

        private TextView textView;

        public MyHolder(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(android.R.id.text1);
        }
    }
}
